/**
 * 
 */
package com.swg.cocobox.filetransfer.data;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;

import com.swg.cocobox.client.WriterClient;

/**
 * @author satriaprayoga
 *
 */
public class DataTransfer extends WriterClient {

	public DataTransfer() throws IOException {
		super();
	}
	
	public void transfer(TransferRequest request)throws IOException{
		SocketChannel socketChannel=initConnection(request.getDestAddress(), request.getPort());
		byte[] data=request.sinkData();
		synchronized (pendingData) {
			List<ByteBuffer> queue=pendingData.get(socketChannel);
			if(queue==null){
				queue=new ArrayList<ByteBuffer>();
				pendingData.put(socketChannel, queue);
			}
			queue.add(ByteBuffer.wrap(data));
		}
		selector.wakeup();
	}

	
}
